using System;
using System.Drawing;

namespace StarSkipGame
{
    /// <summary>
    /// 游戏对象基类，包含所有游戏对象的基本属性
    /// </summary>
    public abstract class GameObject
    {
        // 位置和大小
        public float X { get; set; }
        public float Y { get; set; }
        public int Width { get; set; }
        public int Height { get; set; }
        
        // 速度
        public float VelocityX { get; set; }
        public float VelocityY { get; set; }
        
        // 是否活跃
        public bool IsActive { get; set; }
        
        // 边界矩形
        public Rectangle Bounds 
        { 
            get { return new Rectangle((int)X, (int)Y, Width, Height); } 
        }
        
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="x">初始X坐标</param>
        /// <param name="y">初始Y坐标</param>
        /// <param name="width">宽度</param>
        /// <param name="height">高度</param>
        protected GameObject(float x, float y, int width, int height)
        {
            X = x;
            Y = y;
            Width = width;
            Height = height;
            IsActive = true;
        }
        
        /// <summary>
        /// 更新游戏对象状态
        /// </summary>
        /// <param name="deltaTime">时间间隔</param>
        public virtual void Update(float deltaTime)
        {
            if (!IsActive) return;
            
            // 更新位置
            X += VelocityX * deltaTime;
            Y += VelocityY * deltaTime;
        }
        
        /// <summary>
        /// 绘制游戏对象
        /// </summary>
        /// <param name="g">绘图对象</param>
        public abstract void Draw(Graphics g);
        
        /// <summary>
        /// 检查与其他游戏对象的碰撞
        /// </summary>
        /// <param name="other">其他游戏对象</param>
        /// <returns>是否发生碰撞</returns>
        public virtual bool CollidesWith(GameObject other)
        {
            if (!IsActive || !other.IsActive) return false;
            
            return Bounds.IntersectsWith(other.Bounds);
        }
    }
} 